package net.bblot.lottery.push;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;

import net.bblot.lottery.activity.MainActivity;
import net.bblot.lottery.util.Logger;

import org.json.JSONObject;

public class PushUtil {

	public static void saveClintId(Context context, String clintId) {
		SharedPreferences sPreferences = context.getSharedPreferences("PushUtil", Context.MODE_PRIVATE);
		sPreferences.edit().putString("clintId", clintId).commit();
	}

	public static String getClientId(Context context) {
		SharedPreferences sPreferences = context.getSharedPreferences("PushUtil", Context.MODE_PRIVATE);
		return sPreferences.getString("clintId", "");
	}

	public static void processData(String data, Context context) {
		try {
			Logger.e("PushUtil", data);
			JSONObject jObject = new JSONObject(data);
			String category = jObject.getString("category");
			if ("openPrize".equals(category)) {//开奖
				JSONObject jcontent = jObject.getJSONObject("content");
				String summary = jcontent.getString("summary");
				Intent intent = new Intent(context, MainActivity.class);
				Uri uri = Uri.parse("cptoback://?pageName=numKaijiang&type=" + summary);
				intent.setData(uri);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(intent);
			}else if("remind".equals(category)){
				JSONObject jcontent = jObject.getJSONObject("content");
				String id = jcontent.getString("id");
				Intent intent = new Intent(context, MainActivity.class);
				Uri uri = Uri.parse("cptoback://?pageName=redBag&id=" + id);
				intent.setData(uri);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(intent);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
